<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<div class="dialog-warp-ajax">
<form action="" id="flowCreate">
    <table class="dggui-table-info">
        <tbody>
        <tr>
            <th><span class="required">生产事业部：</span></th>
            <td id="productOrg">
                <select id="orgId" name="orgId" class="dggui-select">
                </select>
            </td>
        </tr>
        <tr>
            <th><span class="required">业务类型：</span></th>
            <td>
                <input type="hidden" id="typeCodeAddHidden" name="typeCodeAdd"  class="plug-in-code">
                <div name="typeCodeAdds" id="typeCodeAdd"></div>
            </td>
        </tr>
        <tr>
            <th><span class="required">业务办理周期：</span></th>
            <td>
                <div class="unit-warp">
                    <input type="number" id="blDate" class="dggui-input" max="10000" min="0" name="blDate">
                    <span class="unit">天</span>
                </div>
            </td>
        </tr>
        <tr>
            <th><span class="required">工作日/自然日：</span></th>
            <td>
                <select class="dggui-select" name="isnaturalorworkday">
                    <option value="1">工作日</option>
                    <option value="2">自然日</option>
                </select>
            </td>
        </tr>
        <tr>
            <th><span class="required">审核级数：</span></th>
            <td>
                <select class="dggui-select" name="examinGrade">
                    <option value="1" selected="selected">一级</option>
                    <option value="2">二级</option>
                    <option value="3">三级</option>
                    <option value="4">四级</option>
                    <option value="5">五级</option>
                    <option value="6">六级</option>
                    <option value="7">七级</option>
                    <option value="8">八级</option>
                    <option value="9">九级</option>
                    <option value="10">十级</option>
                </select>
            </td>
        </tr>
        </tbody>
    </table>
    <%--<input type="hidden" name="flowId" value="${rzFlow.id}"/>--%>
</form>
</div>
<script type="text/javascript">
    //debugger
    //console.dir(dggui);
    dggui.use(['select2','distpicker'], function (){
        var select2 = dggui.select2;
        var distpicker=dggui.distpicker;
        //初始化所属生产事业部
        syb("#orgId");
        select2.render({
            placeholder: "请选择",
            elem: $('#orgId'),
            allowClear: true,
            width: "190px"
        });
        //初始化业务类型及产品
        distpicker.render({
            url: "${basePath}/rzsc/common/tree_book_list.do?code=BUS_YT_DK&&type=2&&level=2", // 请求地址
            elem: '#typeCodeAdd', // 容器Id
            type:2,
            placeholder: '选择业态',
            defaultParentCode:'BUS_YT_DK',
           /* callback:function () {
                var code = $("#typeCodeAdd .plug-in-code").val();
                initProductCode("#productCode",code);
                select2.render({
                    placeholder: "请选择",
                    allowClear: true,
                    elem: $('#productCode'),
                    width: "190px"
                });
            }*/
        });
    });


    function flowCreate(index) {
        var addressDeptId = $('[name="orgId"]').val();
        var busYtCode = $('#typeCodeAdd .plug-in-code').val();
        $("#typeCodeAddHidden").val(busYtCode);
        var blDate = $('[name="blDate"]').val();
        //var isnaturalorworkday = $('[name="isnaturalorworkday"]').val();
        //var examinGrade = $('[name="examinGrade"]').val();
        //var busYtName = $('[name="typeCodeAdd"]').find("option:selected").text();
        //var busYtName = $('[name="typeCodeAdd"]').text();
        var reg = /^[1-9]\d*$/;
        if (!addressDeptId) {
            dggui.dialog.tip('请选择所属事业部！',$('#productOrg'));
            return;
        }
        if (!busYtCode) {
            dggui.dialog.tip('请选择业态！',$('#typeCodeAdd'));
            return;
        }
        if(!reg.test(blDate)){
            dggui.dialog.tip('请输入正确的业务办理周期！',$('#blDate'));
            return;
        }
        if(blDate==0){
            dggui.dialog.tip('办理周期不能为零！',$('#blDate'));
            return;
        }
        if (!blDate) {
            dggui.dialog.tip('请选择业务办理周期！',$('#blDate'));
            return;
        }
        if(parseInt(blDate)>10000){
            dggui.dialog.tip('业务办理周期不能大于10000天！',$('#blDate'));
            return;
        }

       /* if (!isIntGte('[name="blDate"]', false)) return flag = false;
        if (!isInLength('[name="blDate"]', 0, 5)) return flag = false;*/
        var params = $('#flowCreate').serializeArray();
        dggui.dialog.loading();
        $.ajax({
            type: 'POST',
            async: true,
            data: params,
            url: sysInfo.basePath + '/rzsc/flow/create_flow_save.do',
            dataType: 'JSON',
            success: function (data) {
                dggui.dialog.loading('close');
                if (data.code == 0) {
                    dggui.dialog.succeed('操作成功！');
                    layer.close(index);
                    //刷新列表
                    reloadTable($('#flowNode'),"reloadFalse");
                    /*search($('#flowNode'));*/
                } else {
                    dggui.dialog.errors(data.msg);
                }
            },
            error: function () {
                dggui.dialog.loading('close');
                dggui.dialog.errors('保存失败，请联系管理员！！');
            }
        })
    }

</script>
